import { request } from './request'
import type { News, PaginatedResponse } from '@/types'

// 获取新闻列表
export const getNewsList = (params: {
  page: number
  page_size: number
  category_id?: number
  status?: number
}) => {
  return request<PaginatedResponse<News>>({
    url: '/admin/news',
    method: 'get',
    params
  })
}

// 获取新闻详情
export const getNews = (id: number) => {
  return request<News>({
    url: `/admin/news/${id}`,
    method: 'get'
  })
}

// 创建新闻
export const createNews = (data: Partial<News>) => {
  return request<News>({
    url: '/admin/news',
    method: 'post',
    data
  })
}

// 更新新闻
export const updateNews = (id: number, data: Partial<News>) => {
  return request<News>({
    url: `/admin/news/${id}`,
    method: 'put',
    data
  })
}

// 删除新闻
export const deleteNews = (id: number) => {
  return request({
    url: `/admin/news/${id}`,
    method: 'delete'
  })
}

